package com.ruslan.magaz.web.validation;

import java.lang.annotation.Annotation;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.joda.time.DateTime;
import org.joda.time.Period;
import org.springframework.beans.factory.annotation.Autowired;

import com.ruslan.magaz.domain.User;
import com.ruslan.magaz.service.UserService;

public class TooYoungValidator implements
		ConstraintValidator<TooYoung, Date> {

	@Autowired
	private UserService userService;

	@Override
	public void initialize(TooYoung constraint) {

	}

	@Override
	public boolean isValid(Date date, ConstraintValidatorContext context) {
		if (date == null){
			return true;
		}
		DateTime old = new DateTime(date);
		DateTime now = new DateTime();
		Period period =new Period(old, now);
		System.out.println(date);
		if (period.getYears() < 16){
			return false;
		}
		return true;
	}
}